package com.wicket.okrapp.processor.timer;

import com.wicket.okrapp.biz.service.GridCalculateService;
import com.wicket.okrapp.biz.service.TimingTaskService;
import com.wicket.okrapp.biz.service.dto.req.*;
import com.wicket.okrapp.common.util.RedisUtil;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class LocalTimmerProcessor {
    @Autowired
    TimingTaskService timingTaskService;

    @Autowired
    GridCalculateService gridCalculateService;

    @Autowired
    RedisUtil redisUtil;

    @Scheduled(cron = "0 0 1 * * *")
    //D3-3定时更新周期阶段当前周期等调度
    @Trace(operationName = "定时任务-D3定时自动提交全模板汇报任务并审核处理消息(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public void timingAutoReportTasks() {
        System.out.println("定时任务-D3定时自动提交全模板汇报任务并审核处理消息(公共)  -开始"+new Date());
        boolean bLock = redisUtil.getLock("10250","10250",7200);
        try{
            if(bLock){
                TimingAutoReportAllTempTaskAndAuditComReqDto reqDto = new TimingAutoReportAllTempTaskAndAuditComReqDto();
                timingTaskService.timingAutoReportAllTempTaskAndAuditCom(reqDto);
                System.out.println("定时任务-D3定时自动提交全模板汇报任务并审核处理消息(公共)  -进行结束"+new Date());
            }
        }finally {
            if(bLock){
                redisUtil.releaseLock("10250","10250");
                System.out.println("定时任务-D3定时自动提交全模板汇报任务并审核处理消息(公共)  -结束解锁"+new Date());
            }
        }
    }

    @Scheduled(cron = "0 0 1 * * *")
    //D3定时生成简易生成汇报任务
    @Trace(operationName = "定时任务-D3定时生成简易生成汇报任务")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public void timingAddSimpleAddReportTask() {
        System.out.println("定时任务-D3定时生成简易生成汇报任务  -开始"+new Date());
        boolean bLock = redisUtil.getLock("3280","3280",14400);
        try{
            if(bLock){
                TimingAddSimpleAddReportTaskReqDto reqDto = new TimingAddSimpleAddReportTaskReqDto();
                timingTaskService.timingAddSimpleAddReportTask(reqDto);
                System.out.println("定时任务-D3定时生成简易生成汇报任务  -进行结束"+new Date());
            }
        }finally {
            if(bLock){
                redisUtil.releaseLock("3280","3280");
                System.out.println("定时任务-D3定时生成简易生成汇报任务  -结束解锁"+new Date());
            }
        }
    }

    @Scheduled(cron = "0 0 1 * * *")
    //D3-3定时更新周期阶段当前周期等调度
    @Trace(operationName = "定时任务-D3-3定时更新周期阶段当前周期等调度")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public void timingRefreshStageCurrentCycleDispatch() {
        System.out.println("定时任务-D3-3定时更新周期阶段当前周期等调度  -开始"+new Date());
        boolean bLock = redisUtil.getLock("3362","3362",7200);
        try{
            if(bLock){
                TimingRefreshStageCurrentCycleDispatchReqDto reqDto = new TimingRefreshStageCurrentCycleDispatchReqDto();
                timingTaskService.timingRefreshStageCurrentCycleDispatch(reqDto);
                System.out.println("定时任务-D3-3定时更新周期阶段当前周期等调度  -进行结束"+new Date());
            }
        }finally {
            if(bLock){
                redisUtil.releaseLock("3362","3362");
                System.out.println("定时任务-D3-3定时更新周期阶段当前周期等调度  -结束解锁"+new Date());
            }
        }
    }

//    @Scheduled(cron = "0 0 1 * * *")
//    //D3-3定时更新任务逾期等调度
//    @Trace(operationName = "定时任务-D3-3定时更新任务逾期等调度")
//    @Tags({@Tag(key = "参数", value = "arg[0]"),
//            @Tag(key = "返回值", value = "returnedObj")})
//    public void timingRefreshTaskOverdueDispatch() {
//        boolean bLock = redisUtil.getLock("3363","3363",7200);
//        try{
//            if(bLock){
//                TimingRefreshTaskOverdueDispatchReqDto reqDto = new TimingRefreshTaskOverdueDispatchReqDto();
////                timingTaskService.timingRefreshTaskOverdueDispatch(reqDto);
//            }
//        }finally {
//            if(bLock){
//                redisUtil.releaseLock("3363","3363");
//            }
//        }
//    }

//    @Scheduled(cron = "0 0 1 * * *")
//    //D3-3更新四棵树偏差天数等调度(公共)
//    @Trace(operationName = "定时任务-D3-3更新四棵树偏差天数等调度(公共)")
//    @Tags({@Tag(key = "参数", value = "arg[0]"),
//            @Tag(key = "返回值", value = "returnedObj")})
//    public void refreshFourTreeDeviationDaysDispatchCom() {
//
//
//        boolean bLock = redisUtil.getLock("3357","3357",7200);
//        try{
//            if(bLock){
//                RefreshFourTreeDeviationDaysDispatchComReqDto reqDto = new RefreshFourTreeDeviationDaysDispatchComReqDto();
////                timingTaskService.refreshFourTreeDeviationDaysDispatchCom(reqDto);
//            }
//        }finally {
//            if(bLock){
//                redisUtil.releaseLock("3357","3357");
//            }
//        }
//    }

//    @Scheduled(cron = "0 0 1 * * *")
//    //D3-定时计算全网内容标准数据(公共)
//    @Trace(operationName = "定时任务-D3-定时计算全网内容标准数据(公共)")
//    @Tags({@Tag(key = "参数", value = "arg[0]"),
//            @Tag(key = "返回值", value = "returnedObj")})
//    public void timingCalcAllDataCom() {
//
//
//        boolean bLock = redisUtil.getLock("6378","6378",7200);
//        try{
//            if(bLock){
//                TimingCalcAllDataComReqDto reqDto = new TimingCalcAllDataComReqDto();
//                gridCalculateService.timingCalcAllDataCom(reqDto);
//            }
//        }finally {
//            if(bLock){
//                redisUtil.releaseLock("6378","6378");
//            }
//        }
//    }




//    @Scheduled(cron = "0 0 0 * * ?") // 每天凌晨12点执行一次dd
//    public void doTask() {
//        // 定时任务的逻辑处理
//
//
//
//
//    }
}
